package fr.cephb.joperon.core.bio;

import fr.cephb.joperon.core.entities.DnaSeq;
/**
 * A sequence used to decode a sequence stored & packed by Mario Foglio in Operon 
 * @author lindenb
 *
 */
public class DNASEQArray
extends AbstractBiologicalSequence
implements DNASequence
{
private String name;
private byte buffer[];
/**
 * Constructor
 * @param name sequence name
 * @param array array of byte where the sequence is stored
 * @param byteIndex index of the information
 * @param bytesLength length of the information
 */
public DNASEQArray(String name,byte array[],int byteIndex,int bytesLength)
	{
	this.name=name;
	if(bytesLength%DnaSeq.SIZEOF!=0) throw new IllegalArgumentException(
		"Expected length of byte array to be a multiple of sizeof(DnaSeq)="
		+DnaSeq.SIZEOF
		);
	this.buffer= new byte[bytesLength];
	System.arraycopy(array, byteIndex, this.buffer, 0, bytesLength);
	}

/** get the DNASEQ object at the given index
 * 
 * @param index the base position
 * @return
 */
public DnaSeq getDnaSeqAt(int index)
	{
	return new DnaSeq(this.buffer,index*DnaSeq.SIZEOF);
	}

private void debugAt(int index)
	{
	 getDnaSeqAt(index).debug();
	}
/** ignore please */
public void debug()
	{
	for(int i=0;i< 200 && i< size();++i)
		{
		System.err.print("Index="+i+"\t");
		debugAt(i);
		}
	}


@Override
/** calls getDnaSeqAt(index).getBase(); */
public char at(int index) {
	return getDnaSeqAt(index).getBase();
	}

@Override
public String getName() {
	return this.name;
	}

@Override
public int size() {
	return this.buffer.length/DnaSeq.SIZEOF;
	}

}
